package com.andy.controller;

import com.andy.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private LoginService loginService;

    @RequestMapping("/")
    public String loginPage(){
        return "login";
    }


    /**
     * 执行login动作
     * @param httpSession
     * @param username
     * @param password
     * @return
     * @throws Exception
     */
    @RequestMapping("/login")
    @ResponseBody
    public String login(HttpSession httpSession, String username, String password) throws Exception {
        //尝试登录
        loginService.login(username, password);

        httpSession.setAttribute("session_username", username);

        return "hello";
    }

}
